////Balanced Stone Heaps
////
//
////
//
////#include <iostream>
////#include <cstring>
////#include <algorithm>
////#include <vector>
////#include <cmath>
////#include <unordered_map>
////#include <unordered_set>
////#include <map>
////#include <set>
////#include <queue>
////#include <stack>
////#include <deque>
////#include <functional>
////#include <climits>
////
////#define quickio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
////#define endl "\n"
////
////using namespace std;
////typedef long long ll;
////
////const int N = 2e5 + 5;
////ll arr[N];
////
////int main()
////{
////	int t;
////	cin >> t;
////	int n;
////	while (t--)
////	{
////		cin >> n;
////		ll flag = 0, flagnum;
////		for (int i = 1; i <= n; i++)
////		{
////			cin >> arr[i];
////
////			if (flag == 0 && i >= 3 && arr[i] < 3)
////			{
////				flag = 1;
////				flagnum = arr[i];
////			}
////
////			if (flag == 1 && arr[i] < flagnum)
////				flagnum = arr[i];
////		}
////
////		if (flag == 1)
////		{
////			cout << flagnum << endl;
////			continue;
////		}
////
////		ll minn = LLONG_MAX;
////		if (n < 3)
////		{
////			for (int i = 1; i <= n; i++)
////			{
////				if (arr[i] < minn)
////					minn = arr[i];
////			}
////			cout << minn << endl;
////		}
////		else
////		{
////			ll d;
////			for (int i = 3; i <= n; i++)
////			{
////				d = arr[i] / 3;
////				arr[i - 1] += d;
////				arr[i - 2] += 2 * d;
////				arr[i] -= 3 * d;
////			}
////
////			for (int i = 1; i <= n; i++)
////			{
////				if (arr[i] < minn)
////					minn = arr[i];
////			}
////			cout << minn << endl;
////		}
////	}
////	return 0;
////}
//
//
//#include <iostream>
//#include <cstring>
//#include <algorithm>
//#include <vector>
//#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <map>
//#include <set>
//#include <queue>
//#include <stack>
//#include <deque>
//#include <functional>
//#include <climits>
//
//#define quickio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//#define endl "\n"
//
//using namespace std;
//typedef long long ll;
//
//const int N = 2e5 + 5;
//ll arr[N];
//
//int main()
//{
//	int t;
//	cin >> t;
//	int n;
//	while (t--)
//	{
//		cin >> n;
//		ll flag = 0, flagnum;
//		int booknum = INT_MAX, booknumi;
//		for (int i = 1; i <= n; i++)
//		{
//			cin >> arr[i];
//
//			if (flag == 0 && i >= 3 && arr[i] < 3)
//			{
//				flag = 1;
//				flagnum = arr[i];
//			}
//
//			if (flag == 1 && arr[i] < flagnum)
//				flagnum = arr[i];
//
//			if (i >= 3 && arr[i] < booknum)
//			{
//				booknum = arr[i];
//				booknumi = i;
//			}
//		}
//
//		if (flag == 1)
//		{
//			cout << flagnum << endl;
//			continue;
//		}
//
//		ll minn = LLONG_MAX;
//		if (n < 3)
//		{
//			for (int i = 1; i <= n; i++)
//			{
//				if (arr[i] < minn)
//					minn = arr[i];
//			}
//			cout << minn << endl;
//		}
//		else
//		{
//			ll d;
//			d = arr[booknumi] / 3;
//			arr[booknumi - 1] += d;
//			arr[booknumi - 2] += 2 * d;
//			arr[booknumi] -= 3 * d;
//
//			for (int i = 1; i <= n; i++)
//			{
//				if (arr[i] < minn)
//					minn = arr[i];
//			}
//			cout << minn << endl;
//		}
//	}
//	return 0;
//}
